package com.diaohw.platform.framework.redis.config;

import jakarta.annotation.Resource;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;

/**
 * @author 刁海文
 * @Remark
 * @since 2023/6/25 21:37
 */
@Configuration
public class CacheManagerConfig implements CachingConfigurer {
    @Resource
    RedisConnectionFactory factory;

    @Override
    public CacheManager cacheManager() {
        return RedisCacheManager.builder(factory)
                .build();
    }

    @Override
    public CacheResolver cacheResolver() {
        return CachingConfigurer.super.cacheResolver();
    }

    @Override
    public KeyGenerator keyGenerator() {
        return (target, method, params) -> null;
    }

    @Override
    public CacheErrorHandler errorHandler() {
        return CachingConfigurer.super.errorHandler();
    }
}
